import Configer from './types/configer'
import Phaser from 'phaser'
import 'phaser/plugins/spine/dist/SpinePlugin'

import Boot from './scenes/Boot'
import Preloader from './scenes/Preloader'
import Login from './scenes/Login'
import Game1V1 from './scenes/Game1V1'
import Dashboard from './scenes/Dashboard'
import Hall from './scenes/Hall'
import Room from './scenes/Room'
import GameOver from './scenes/GameOver'
import Preparation from './scenes/Preparation'
import MapTest from './scenes/MapTest'
import NetClient from './types/NetClient'

// let clientWidth = window.innerWidth;
// let clientHeight = window.innerHeight;
let clientWidth = document.body.offsetWidth;
let clientHeight = document.body.offsetHeight;
console.log(clientWidth, clientHeight)


/** 创建网络组件并挂到windows节点上 */
window.client = new NetClient(Configer.GAME_SERVICE_WEBSOCKET_ADDRESS);
window.client.onConnect = function () {
	window.closeLoading();
}
window.client.onDisconnect = function () {
	window.loading();
}


if (clientWidth < clientHeight) {
	alert('请切换横屏模式');
}


const config: Phaser.Types.Core.GameConfig = {
	type: Phaser.AUTO,
	parent: 'main',
	width: clientWidth,
	height: clientHeight,
	physics: {
		default: 'matter',
		matter: {
			gravity: { y: 0 },
			debug: false,
		},
	},
	input: {
		activePointers: 2  // 启用多点触摸支持
	},
	scene: [
		Boot,
		Preloader,
		Dashboard,
		Login,
		Room,
		Hall,
		Preparation,
		Game1V1,
		GameOver,
		MapTest
	],
	dom: {
		createContainer: true
	},
	plugins: {
		scene: [
			{ key: 'SpinePlugin', plugin: window.SpinePlugin, mapping: 'spine' }
		]
	},
}


let game = new Phaser.Game(config)
window.game = game;
export default game;
